﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L06
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            { 
            Triangle triangle1 = new Triangle(1, 1, 1);
            //Triangle triangle2 = new Triangle(1, 0, 1);

            Console.WriteLine("三角形周长为{0}",triangle1 .Perimeter );
            Console.WriteLine("三角形面积为{0}",triangle1 .Area );
                //Console.WriteLine("三角形周长为{0}",triangle2 .Perimeter );
                //Console.WriteLine("三角形面积为{0}",triangle2.Area );
            }
            catch (ArgumentException)
            {
                Console.WriteLine("指定的边长不满足构造三角形的条件");
            }

            Console.ReadKey();
        }

        public class Triangle
        {
            public float A { get; set; }
            public float B { get; set; }
            public float C { get; set; }

            public Triangle(float a, float b, float c)
            {
                if (!((a > 0) && (b > 0) && (c > 0) && (a + b > c) && (a + c > b) && (c + b > a)))
                throw new ArgumentException();//抛出异常出错
                    A = a;
                    B = b;
                    C = c; 
            }

            public float Perimeter//属性
            {
                get { return (A + B + C); }
            }

            public float Area
            {
                get { return (float )Math.Sqrt ((A + B+ C)*(A + B - C)*(A -B + C)*(C+ B -A)) /4; }
            }

        }
    }
}
